package com.gtl.meishi.util;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.gtl.meishi.bean.CotegroyEntity;
import com.gtl.meishi.bean.MediaEntity;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangke on 16/7/9.
 */
public class JsonUtil {

    /**
     * 获取种类网络数据
     */
public static   List<CotegroyEntity>  getCotogroy(String path, Context context){

    List<CotegroyEntity> listCotegroys=null;
    try {
        String  jsonStr=  OkHttpUtil.getStr(context,path);
        Gson gson=new Gson();
        Type listType = new TypeToken<List<CotegroyEntity>>() {}.getType();
        listCotegroys=new ArrayList<>();
        listCotegroys = gson.fromJson(jsonStr, listType);

       Log.i("TAG",listCotegroys.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return  listCotegroys;

}
    /**
     * 获取列表信息
     */
public static   List<MediaEntity>  getMediaEntity(String path, Context context,int page,CotegroyEntity cotegroyEntity){

    path+="?type="+cotegroyEntity.getType()+"&&id="+cotegroyEntity.getId()+"&&count=20&&page="+page;
    Log.i("TAG",path);
    List<MediaEntity> listMediaEntity=null;
    try {
        String  jsonStr=  OkHttpUtil.getStr(context,path);
        Gson gson=new Gson();
        Type listType = new TypeToken<List<MediaEntity>>() {}.getType();
        listMediaEntity=new ArrayList<>();
        Log.i("TAG",jsonStr);
      listMediaEntity = gson.fromJson(jsonStr, listType);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return  listMediaEntity;

}
public static   List<MediaEntity>  getMediaEntityOne(String path, Context context,int page,CotegroyEntity cotegroyEntity){

    path+="?type="+cotegroyEntity.getType()+"&&id="+cotegroyEntity.getId()+"&&count=1&&page="+page;
    Log.i("TAG",path);
    List<MediaEntity> listMediaEntity=null;
    try {
        String  jsonStr=  OkHttpUtil.getStr(context,path);
        Gson gson=new Gson();
        Type listType = new TypeToken<List<MediaEntity>>() {}.getType();
        listMediaEntity=new ArrayList<>();
        Log.i("TAG",jsonStr);
      listMediaEntity = gson.fromJson(jsonStr, listType);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return  listMediaEntity;

}




    /**
     *  测试获取媒体信息
     */
//public static   List<MediaEntity>  getMediaEntity(String path, Context context,int page){
//
//    path+="?type=1&&id=1&&count=20&&page="+page;
//    Log.i("TAG",path);
//    List<MediaEntity> listMediaEntity=null;
//    try {
//        String  jsonStr=  OkHttpUtil.getStr(context,path);
//        Gson gson=new Gson();
//        Type listType = new TypeToken<List<MediaEntity>>() {}.getType();
//        listMediaEntity=new ArrayList<>();
//        Log.i("TAG",jsonStr);
//      listMediaEntity = gson.fromJson(jsonStr, listType);
//    } catch (IOException e) {
//        e.printStackTrace();
//    }
//    return  listMediaEntity;
//
//}



        








}
